//
//  BLInfoInputController.m
//  Byelone
//
//  Created by 乔小乔 on 2021/1/23.
//

#import "BLInfoInputController.h"
#import "BLInfoCommonCell.h"
#import "BLInfoInputCell.h"
#import "BLInfoSelectCell.h"
#import "BLInfoTestController.h"

#import "BLInfoModel.h"
#import "BLSheetModel.h"

static NSString *reuse_BLInfoCommonCell = @"Reuse_BLInfoCommonCell";
static NSString *reuse_BLInfoInputCell = @"Reuse_BLInfoInputCell";
static NSString *reuse_BLInfoSelectCell = @"Reuse_BLInfoSelectCell";
@interface BLInfoInputController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property (nonatomic, strong) UITableView *tableViewList;
@property (nonatomic, strong) NSMutableArray *arrayData;
@property (nonatomic, assign) BOOL isOpen;

@property (nonatomic, strong) UIView *viewBottom;

@property (nonatomic, strong) BLInfoInputModel *baseData;//填写基本信息
@property (nonatomic, strong) BLInfoInputDetailModel *detailData;//填写详细信息

@property (nonatomic, strong) BLInfoBaseInfo *baseInfo;//获取到的个人基本信息
@property (nonatomic, strong) BLInfoDetailInfo *detailInfo;//获取到的个人详细信息

@property (nonatomic, strong) BLInfoConfigModel *configModel;
@property (nonatomic, strong) UITextField *currentText;

@property (nonatomic, strong) UITextField *textNickName;
@property (nonatomic, strong) UITextField *textHeight;
@property (nonatomic, strong) UITextField *textWight;
@property (nonatomic, strong) UITextField *textSchool;
@property (nonatomic, strong) UITextField *textMajor;
@property (nonatomic, strong) UITextField *textCompanyName;
@property (nonatomic, strong) UITextField *textFieldPosition;

@property (nonatomic, strong) NSString *strDate;
@property (nonatomic, strong) NSString *strArea;
@property (nonatomic, strong) NSString *strHomeTown;
@property (nonatomic, strong) NSString *strPostion;
@property (nonatomic, strong) NSString *strIndustry;
@property (nonatomic, strong) NSArray *indusList;//当前行业的list

@property (nonatomic, strong) UIButton *btnTest;
@property (nonatomic, strong) UIButton *btnHome;

@end

@implementation BLInfoInputController

- (void)viewDidLoad {
    [super viewDidLoad];
    //    type:--1:性别,2:选择类型,3:输入类型-ismust:1必填 unit:单位
    self.navigationItem.title = @"完善信息";
    self.arrayData = [NSMutableArray new];
    [self disposeData];
    [self.arrayData addObjectsFromArray:@[@{@"title":@"基本信息",
                                            @"data":@[@{@"title":@"昵称",@"type":@"3",@"ismust":@"1"},@{@"title":@"出生日期",@"type":@"2"},@{@"title":@"性别",@"type":@"1"},@{@"title":@"身高",@"type":@"3",@"unit":@" cm"},@{@"title":@"体重",@"type":@"3",@"unit":@" kg"},@{@"title":@"婚姻状态",@"type":@"2"},@{@"title":@"所在地",@"type":@"2"},@{@"title":@"家乡",@"type":@"2"}]},
                                          @{@"title":@"学历工作",                                            @"data":@[@{@"title":@"毕业院校",@"type":@"3"},@{@"title":@"所学专业",@"type":@"3"},@{@"title":@"最高学历",@"type":@"2"},@{@"title":@"从事行业",@"type":@"2"},@{@"title":@"岗位",@"type":@"2"},@{@"title":@"就职公司",@"type":@"3"}]},
                                          @{@"title":@"资产情况",
                                            @"data":@[@{@"title":@"年收入",@"type":@"2"},@{@"title":@"车产",@"type":@"2"},@{@"title":@"房产",@"type":@"2"}]}]];
    [self.view addSubview:self.tableViewList];
    [self.tableViewList reloadData];
    [self getCommonMap];
    
    if (self.isEdit) {
        self.btnHome.hidden = YES;
        [self.btnTest setTitle:@"提交" forState:UIControlStateNormal];
    }
}
- (void)disposeData{
    if ([BLUserManager shareUser].baseInfo) {
//        self.isEdit = YES;
        self.baseInfo = [BLUserManager shareUser].baseInfo;
        self.baseData.nickname = self.baseInfo.nickname;
        self.baseData.birthday = self.baseInfo.birthday;
        self.baseData.gender = self.baseInfo.gender;
        self.baseData.height = self.baseInfo.height;
        self.baseData.weight = self.baseInfo.weight;
        self.baseData.marryStatus = self.baseInfo.marryStatus;
        self.baseData.livingAreaId = self.baseInfo.livingAreaId;
        self.baseData.livingCityId = self.baseInfo.livingCityId;
        self.baseData.homeAreaId = self.baseInfo.homeAreaId;
        self.baseData.homeCityId = self.baseInfo.homeCityId;
        
        if (![NSString blIsBlankString:self.baseInfo.homeAreaName]) {
            self.strHomeTown = [NSString stringWithFormat:@"%@ %@",self.baseInfo.homeAreaName,self.baseInfo.homeCityName];
        }
        if (![NSString blIsBlankString:self.baseInfo.livingAreaName]) {
            self.strArea = [NSString stringWithFormat:@"%@ %@",self.baseInfo.livingAreaName,self.baseInfo.livingCityName];
        }
        if (self.baseInfo.birthday>0) {
            self.strDate = [NSDate stringYearMonthDayWithTimeStamp:[NSString stringWithFormat:@"%ld",self.baseInfo.birthday]];
        }
    }
    if ([BLUserManager shareUser].detailInfo) {
//        self.isEdit = YES;
        self.detailInfo = [BLUserManager shareUser].detailInfo;
        self.detailData.school = self.detailInfo.school;
        self.detailData.major = self.detailInfo.major;
        self.detailData.grade = self.detailInfo.grade;
        self.detailData.industry = self.detailInfo.industry;
        self.detailData.position = self.detailInfo.position;
        self.detailData.companyName = self.detailInfo.companyName;
        self.detailData.yearIncome = self.detailInfo.yearIncome;
        self.detailData.car = self.detailInfo.car;//车有无
        self.detailData.realeState = self.detailInfo.realeState;
        self.strPostion = self.detailInfo.positionName;
        self.strIndustry = self.detailInfo.industryName;
    }
}
#pragma mark - method
- (void)clickMore{
    self.isOpen = YES;
    [self.tableViewList reloadData];
}
- (void)setCorner:(UIView *)view size:(CGSize)size rect:(UIRectCorner)rectCorner{
    CGRect frame = CGRectMake(0, 0, BL_WINDOW_WIDTH-20, 48);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:rectCorner cornerRadii:size];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = frame;
    //赋值
    maskLayer.path = maskPath.CGPath;
    
    view.layer.mask = maskLayer;
}

- (void)clickToTest{
    if (self.currentText) {
        [self.currentText resignFirstResponder];
        self.currentText = nil;
    }
    if (self.isEdit) {
        [self submit:^{
            [[BLHUD shareHud]showtip:@"提交成功"];
        }];
    }else{
        [self submit:^{
            BLInfoTestController *vc = [[BLInfoTestController alloc]init];
            vc.loginBlock = self.loginBlock;
            vc.testType = BLInfoTestTypeTrait;
            [self.navigationController pushViewController:vc animated:YES];
        }];
    }
}
- (void)clickToHome{
    if (self.currentText) {
        [self.currentText resignFirstResponder];
        self.currentText = nil;
    }
    [self submit:^{
        [self dismissViewControllerAnimated:YES completion:^{
            UINavigationController *nv = [BLTool getCurrentNavigationController];
            nv.tabBarController.selectedIndex = 0;
        }];
    }];
}
- (void)submit:(void(^)(void))over{
    self.baseData.nickname = self.textNickName.text;
    if (![NSString blIsBlankString:self.textHeight.text]) {
        self.baseData.height = self.textHeight.text;
    }
    if (![NSString blIsBlankString:self.textWight.text]) {
        self.baseData.weight = self.textWight.text;
    }
    if (![NSString blIsBlankString:self.textSchool.text]) {
        self.detailData.school = self.textSchool.text;
    }
    if (![NSString blIsBlankString:self.textMajor.text]) {
        self.detailData.major = self.textMajor.text;
    }
    if (![NSString blIsBlankString:self.textCompanyName.text]) {
        self.detailData.companyName = self.textCompanyName.text;
    }
    if (self.baseData.gender<1) {
        [[BLHUD shareHud]showtip:@"请选择性别"];
        return;
    }
    NSDictionary *dict = [self.baseData mj_keyValues];
    [BLHttpTool postWithPath:BL_USER_SETBASEINFO params:dict successBlock:^(NSDictionary * _Nonnull obj) {
        if (self.isOpen) {
            NSDictionary *dictDetail = [self.detailData mj_keyValues];
            [BLHttpTool postWithPath:BL_USER_SETDETAIL params:dictDetail successBlock:^(NSDictionary * _Nonnull obj) {
                if (over) {
                    over();
                }
                [BLUserManager shareUser].registerStep = @"0";//用户信息设置完相当于注册成功，将step设置为0
                [[NSNotificationCenter defaultCenter]postNotificationName:Notification_login object:nil];
            } failedBlock:^(NSURLSessionDataTask * _Nonnull data, NSError * _Nonnull error) {
                
            }];
        }else{
            if (over) {
                over();
            }
            [BLUserManager shareUser].registerStep = @"0";//用户信息设置完相当于注册成功，将step设置为0
            [[NSNotificationCenter defaultCenter]postNotificationName:Notification_login object:nil];
        }
    } failedBlock:^(NSURLSessionDataTask * _Nonnull data, NSError * _Nonnull error) {
        
    }];
    
}
-(void)getCommonMap{
    [BLHttpTool getHttpRequest:BL_COMMON_CONFIG param:@{} finish:^(NSURLSessionDataTask * _Nonnull data, NSDictionary * _Nonnull obj) {
        if (obj) {
            if ([[obj objectForKey:@"code"] integerValue] == 1) {
                NSDictionary * dic = [obj objectForKey:@"content"];
                self.configModel = [BLInfoConfigModel mj_objectWithKeyValues:dic];
                if (self.isEdit) {
                    [self.tableViewList reloadData];
                }
//                [[BLUserManager shareUser] setAliOssConfig:dic];
            }else{
                
            }
        }
    } failedBlock:^(id  _Nonnull data, NSError * _Nonnull error) {
        
    }];
}
//根据类型标题处理数组
- (NSArray *)getAlertArray:(NSString *)title{
    NSMutableArray *alertArray = [NSMutableArray new];
    NSDictionary *dict;
    if ([title isEqualToString:@"婚姻状态"]) {
        dict = self.configModel.marryMap;
    }else if ([title isEqualToString:@"最高学历"]){
        dict = self.configModel.gradeMap;
    }else if ([title isEqualToString:@"年收入"]){
        dict = self.configModel.incomeMap;
    }else if ([title isEqualToString:@"车产"]||[title isEqualToString:@"房产"]){
        dict = @{@"1":@"有",@"0":@"无"};
    }
    NSMutableArray *arrayKeys = [NSMutableArray arrayWithArray:dict.allKeys];
//    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"key" ascending:YES];
//    [arrayKeys sortUsingDescriptors:[NSArray arrayWithObject:sort]];
    for (NSString *keys in arrayKeys) {
        BLCommon_Model_AlertItem *item = [[BLCommon_Model_AlertItem alloc]init];
        item.text = dict[keys];
        item.Id = keys;
        [alertArray addObject:item];
    }
    return alertArray;
}

- (NSArray *)getPosition{
    for (BLInfoIndustryItem *indusItem in self.configModel.industryList) {
        if (indusItem.Id.integerValue == self.detailData.industry) {
            return indusItem.posList;
        }
    }
    return nil;
}

- (void)disposeSelectData:(NSString *)title item:(BLCommon_Model_AlertItem *)item{
    if ([title isEqualToString:@"婚姻状态"]) {
        self.baseData.marryStatus = item.Id.integerValue;
    }else if ([title isEqualToString:@"最高学历"]){
        self.detailData.grade = item.Id.integerValue;
    }else if ([title isEqualToString:@"年收入"]){
        self.detailData.yearIncome = item.Id.integerValue;
    }else if ([title isEqualToString:@"车产"]){
        self.detailData.car = item.Id.integerValue;
    }else if ([title isEqualToString:@"房产"]){
        self.detailData.realeState = item.Id.integerValue;
    }
}

- (void)textFieldWithText:(UITextField *)textField{
    if (textField == self.textNickName) {
        self.baseData.nickname = textField.text;
    }else if (textField == self.textHeight) {
        self.baseData.height = textField.text;
    }else if (textField == self.textWight) {
        self.baseData.weight = textField.text;
    }else if (textField == self.textSchool) {
        self.detailData.school = textField.text;
    }else if (textField == self.textMajor) {
        self.detailData.major = textField.text;
    }else if (textField == self.textCompanyName) {
        self.detailData.companyName = textField.text;
    }
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.isOpen) {
        return self.arrayData.count;
    }
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary *dict = self.arrayData[section];
    NSArray *array = dict[@"data"];
    return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = self.arrayData[indexPath.section];
    NSArray *array = dict[@"data"];
    NSDictionary *dictItem = array[indexPath.row];
    BLInfoModel *item = [BLInfoModel mj_objectWithKeyValues:dictItem];
//    加圆角，判断圆角
    UIRectCorner rectCorner= UIRectCornerTopLeft|UIRectCornerTopRight;
    CGSize rect = CGSizeMake(5, 5);
    if (indexPath.row == 0) {
        rectCorner = UIRectCornerTopLeft|UIRectCornerTopRight;
        if (indexPath.row == array.count-1) {
            rectCorner = UIRectCornerAllCorners;
        }
    }else if (indexPath.row == array.count-1) {
        rectCorner = UIRectCornerBottomLeft|UIRectCornerBottomRight;
    }else{
        rect = CGSizeMake(0, 0);
    }
//    cell类型
    if ([item.type isEqualToString:@"2"]) {
        BLInfoCommonCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse_BLInfoCommonCell forIndexPath:indexPath];
        //        [cell reloadWithData:nil];
        cell.labelTitle.text = item.title;
        cell.textFieldContent.placeholder = [NSString stringWithFormat:@"请选择您的%@",item.title];
        if ([item.title isEqualToString:@"婚姻状态"]) {
            NSString *Id = [NSString stringWithFormat:@"%ld",self.baseData.marryStatus];
            cell.textFieldContent.text = Id?self.configModel.marryMap[Id]:@"";
        }else if ([item.title isEqualToString:@"最高学历"]) {
            NSString *Id = [NSString stringWithFormat:@"%ld",self.detailData.grade];
            cell.textFieldContent.text = Id?self.configModel.gradeMap[Id]:@"";
        }else if ([item.title isEqualToString:@"年收入"]) {
            NSString *Id = [NSString stringWithFormat:@"%ld",self.detailData.yearIncome];
            cell.textFieldContent.text = Id?self.configModel.incomeMap[Id]:@"";
        }else if ([item.title isEqualToString:@"车产"]) {
            NSString *Id = [NSString stringWithFormat:@"%ld",self.detailData.car];
            cell.textFieldContent.text = Id?(Id.intValue?@"是":@"否"):@"";
        }else if ([item.title isEqualToString:@"房产"]) {
            NSString *Id = [NSString stringWithFormat:@"%ld",self.detailData.realeState];
            cell.textFieldContent.text = Id?(Id.intValue?@"是":@"否"):@"";
        }else if ([item.title isEqualToString:@"出生日期"]) {
            cell.textFieldContent.text = self.strDate;
        }else if ([item.title isEqualToString:@"所在地"]) {
            cell.textFieldContent.text = self.strArea;
        }else if ([item.title isEqualToString:@"家乡"]) {
            cell.textFieldContent.text = self.strHomeTown;
        }else if ([item.title isEqualToString:@"从事行业"]) {
            cell.textFieldContent.text = self.strIndustry;
        }else if ([item.title isEqualToString:@"岗位"]) {
            cell.textFieldContent.text = self.strPostion;
            self.textFieldPosition = cell.textFieldContent;
        }else{
            cell.textFieldContent.text = @"";
        }
        [self setCorner:cell.viewBj size:rect rect:rectCorner];
        return cell;
    }else if ([item.type isEqualToString:@"1"]) {
        BLInfoSelectCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse_BLInfoSelectCell forIndexPath:indexPath];
        
        if (self.baseData.gender == 1) {
            cell.btnBoy.selected = YES;
            cell.btnGirl.selected = NO;
        }else if(self.baseData.gender == 2){
            cell.btnBoy.selected = NO;
            cell.btnGirl.selected = YES;
        }
        cell.labelTitle.text = item.title;
        [self setCorner:cell.viewBj size:rect rect:rectCorner];
        BLWS(weakSelf)
        cell.myBlock = ^(NSInteger index) {
//            101女,102男
            if (index == 101) {
                weakSelf.baseData.gender = 2;
            }else{
                weakSelf.baseData.gender = 1;
            }
        };
        return cell;
    }else{
        BLInfoInputCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse_BLInfoInputCell forIndexPath:indexPath];
        //        [cell reloadWithData:nil];
        cell.labelTitle.text = item.title;
        if ([item.ismust isEqualToString:@"1"]) {
            cell.labelTag.hidden = NO;
        }else{
            cell.labelTag.hidden = YES;
        }
        cell.labelUnit.text = item.unit;
        cell.textFieldContent.placeholder = [NSString stringWithFormat:@"请输入您的%@",item.title];
        [self setCorner:cell.viewBj size:rect rect:rectCorner];
        cell.textFieldContent.delegate = self;
        [cell.textFieldContent addTarget:self action:@selector(textFieldWithText:) forControlEvents:UIControlEventEditingChanged];
        if ([item.title isEqualToString:@"昵称"]) {
            self.textNickName = cell.textFieldContent;
            cell.textFieldContent.text = self.baseData.nickname;
        }else if ([item.title isEqualToString:@"身高"]) {
            self.textHeight = cell.textFieldContent;
            cell.textFieldContent.text = self.baseData.height;
        }else if ([item.title isEqualToString:@"体重"]) {
            self.textWight = cell.textFieldContent;
            cell.textFieldContent.text = self.baseData.weight;
        }else if ([item.title isEqualToString:@"毕业院校"]) {
            self.textSchool = cell.textFieldContent;
            cell.textFieldContent.text = self.detailData.school;
        }else if ([item.title isEqualToString:@"所学专业"]) {
            self.textMajor = cell.textFieldContent;
            cell.textFieldContent.text = self.detailData.major;
        }else if ([item.title isEqualToString:@"就职公司"]) {
            self.textCompanyName = cell.textFieldContent;
            cell.textFieldContent.text = self.detailData.companyName;
        }
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 48;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSDictionary *dict = self.arrayData[section];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, BL_WINDOW_WIDTH, 41)];
    UIView *viewLine = [[UIView alloc]initWithFrame:CGRectMake(10, 13, 4, 15)];
    viewLine.backgroundColor = [UIColor chColorWithHexString:@"#6C72F5"];
    viewLine.layer.cornerRadius = 2;
    viewLine.layer.masksToBounds = YES;
    [view addSubview:viewLine];
    
    UILabel *labelTitle = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 200, 41)];
    labelTitle.font = [UIFont systemFontOfSize:14];
    labelTitle.textColor = [UIColor chColorWithHexString:@"#6C72F5"];
    labelTitle.text = dict[@"title"];
    [view addSubview:labelTitle];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 41;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    if (self.isOpen) {
        view.frame = CGRectMake(0, 0, BL_WINDOW_WIDTH, 0.01);
        return view;
    }
    view.frame = CGRectMake(0, 0, BL_WINDOW_WIDTH, 51);
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake((BL_WINDOW_WIDTH-101)*0.5, 15, 101, 21);
    [btn setTitle:@"完善更多信息" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:11];
    [btn setTitleColor:[UIColor chColorWithHexString:@"#6C72F5"] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 10.5;
    btn.layer.masksToBounds = YES;
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = [UIColor chColorWithHexString:@"#6C72F5"].CGColor;
    [btn addTarget:self action:@selector(clickMore) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (self.isOpen) {
        return 0.01;
    }
    return 51;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.currentText) {
        [self.currentText resignFirstResponder];
        self.currentText = nil;
    }
    
    NSDictionary *dict = self.arrayData[indexPath.section];
    NSArray *array = dict[@"data"];
    NSDictionary *dictItem = array[indexPath.row];
    BLInfoModel *item = [BLInfoModel mj_objectWithKeyValues:dictItem];
    
    if ([item.type isEqualToString:@"2"]) {
        BLInfoCommonCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        
        if ([item.title isEqualToString:@"婚姻状态"]||[item.title isEqualToString:@"最高学历"]||[item.title isEqualToString:@"年收入"]||[item.title isEqualToString:@"车产"]||[item.title isEqualToString:@"房产"]) {
            NSArray *arrayItem = [self getAlertArray:item.title];
            
            BLCommon_Model_AlertItem *cancelItem = [[BLCommon_Model_AlertItem alloc]init];
            cancelItem.type = @"4";
            cancelItem.text = @"取消";
            if (arrayItem.count>0) {
                [BLPickManager showRoomPickView:item.title array:arrayItem select:^(BLCommon_Model_AlertItem * _Nonnull dateDic) {
                    cell.textFieldContent.text = dateDic.text;
                    [self disposeSelectData:item.title item:dateDic];
                }];
            }
        }else if ([item.title isEqualToString:@"从事行业"]||[item.title isEqualToString:@"岗位"]) {
            NSMutableArray *alertArray = [NSMutableArray new];
            if ([item.title isEqualToString:@"从事行业"]) {
                for (BLInfoIndustryItem *indusItem in self.configModel.industryList) {
                    BLCommon_Model_AlertItem *item = [[BLCommon_Model_AlertItem alloc]init];
                    item.text = indusItem.name;
                    item.Id = indusItem.Id;
                    [alertArray addObject:item];
                }
            }else if ([item.title isEqualToString:@"岗位"]) {
                if (self.detailData.industry>0) {
                    NSArray *array = [self getPosition];
                    for (BLInfoPosItem *posItem in array) {
                        BLCommon_Model_AlertItem *item = [[BLCommon_Model_AlertItem alloc]init];
                        item.text = posItem.name;
                        item.Id = posItem.Id;
                        [alertArray addObject:item];
                    }
                }else{
                    [[BLHUD shareHud]showtip:@"请先选择行业"];
                }
                
            }
            
            BLCommon_Model_AlertItem *cancelItem = [[BLCommon_Model_AlertItem alloc]init];
            cancelItem.type = @"4";
            cancelItem.text = @"取消";
            
            if (alertArray.count>0) {
                [BLPickManager showRoomPickView:item.title array:alertArray select:^(BLCommon_Model_AlertItem * _Nonnull dateDic) {
                    cell.textFieldContent.text = dateDic.text;
                    if ([item.title isEqualToString:@"从事行业"]) {
                        if (self.detailData.industry!=dateDic.Id.integerValue) {
                            self.detailData.industry = dateDic.Id.integerValue;
                            self.strIndustry = dateDic.text;
                            self.detailData.position = 0;
                            self.strPostion = @"";
                            self.textFieldPosition.text = @"";
                        }
                    }else{
                        self.detailData.position = dateDic.Id.integerValue;
                        self.strPostion = dateDic.text;
                    }
                }];
            }
        }else{
            if ([item.title isEqualToString:@"出生日期"]) {
                [BLPickManager showDatePickView:^(NSDictionary * _Nonnull dic) {
                    self.strDate = [NSString stringWithFormat:@"%@",dic[@"dateString"]];
                    self.baseData.birthday = [NSString stringWithFormat:@"%@",dic[@"timestamp"]].integerValue;
                    cell.textFieldContent.text = self.strDate;
                }];
            }else if ([item.title isEqualToString:@"所在地"]||[item.title isEqualToString:@"家乡"]) {
                [BLPickManager showAreaPickView:^(NSDictionary * _Nonnull dic) {
                    NSString *str = [NSString stringWithFormat:@"%@ %@",dic[@"area"][@"name"],dic[@"city"][@"name"]];
                    cell.textFieldContent.text = str;
                    if([item.title isEqualToString:@"所在地"]){
                        self.strArea = str;
                        self.baseData.livingAreaId = [NSString stringWithFormat:@"%@",dic[@"area"][@"id"]].integerValue;
                        self.baseData.livingCityId = [NSString stringWithFormat:@"%@",dic[@"city"][@"id"]].integerValue;
                    }else{
                        self.strHomeTown = str;
                        self.baseData.homeAreaId = [NSString stringWithFormat:@"%@",dic[@"area"][@"id"]].integerValue;
                        self.baseData.homeCityId = [NSString stringWithFormat:@"%@",dic[@"city"][@"id"]].integerValue;
                    }
                }];
            }
            
        }
        
    }
}

#pragma mark - textfield
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    self.currentText = textField;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (self.currentText) {
        [self.currentText resignFirstResponder];
        self.currentText = nil;
    }
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if (self.currentText) {
        [self.currentText resignFirstResponder];
        self.currentText = nil;
    }
}
#pragma mark - get
- (UITableView *)tableViewList{
    if (!_tableViewList) {
        _tableViewList = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, BL_WINDOW_WIDTH, BL_CONTENT_HEIGHT) style:UITableViewStyleGrouped];
        [self.view addSubview:_tableViewList];
        _tableViewList.backgroundColor = [UIColor clearColor];
        _tableViewList.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableViewList.delegate = self;
        _tableViewList.dataSource = self;
//        _tableViewList.tableHeaderView = self.bannerView;
        if (@available(iOS 11.0, *)) {
            _tableViewList.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else{
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        [_tableViewList registerNib:[UINib nibWithNibName:@"BLInfoCommonCell" bundle:nil] forCellReuseIdentifier:reuse_BLInfoCommonCell];
        [_tableViewList registerNib:[UINib nibWithNibName:@"BLInfoInputCell" bundle:nil] forCellReuseIdentifier:reuse_BLInfoInputCell];
        [_tableViewList registerNib:[UINib nibWithNibName:@"BLInfoSelectCell" bundle:nil] forCellReuseIdentifier:reuse_BLInfoSelectCell];
        _tableViewList.tableFooterView = self.viewBottom;
    }
    return _tableViewList;
}
- (UIView *)viewBottom{
    if (!_viewBottom) {
        _viewBottom = [[UIView alloc]initWithFrame:CGRectMake(0, 0, BL_WINDOW_WIDTH, 128)];
        _viewBottom.backgroundColor = [UIColor whiteColor];
        
        UIButton *btnToTest = [UIButton buttonWithType:UIButtonTypeCustom];
        btnToTest.frame = CGRectMake(28, 12, BL_WINDOW_WIDTH-56, 46);
        [btnToTest setGradientBackgroundWithColors:@[[UIColor chColorWithHexString:@"#8680FC"],[UIColor chColorWithHexString:@"#6C72F5"]] locations:@[@(0.0f), @(1.0f)]  startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
        [btnToTest setTitle:@"去做性格测试，提高推荐精准度" forState:UIControlStateNormal];
        btnToTest.titleLabel.font = [UIFont systemFontOfSize:16];
        [btnToTest setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btnToTest addTarget:self action:@selector(clickToTest) forControlEvents:UIControlEventTouchUpInside];
        btnToTest.layer.cornerRadius = 23;
        btnToTest.layer.masksToBounds = YES;
        [_viewBottom addSubview:btnToTest];
        self.btnTest = btnToTest;
        
        
        UIButton *btnToHome = [UIButton buttonWithType:UIButtonTypeCustom];
        btnToHome.frame = CGRectMake(28, 70, BL_WINDOW_WIDTH-56, 46);
        [btnToHome setGradientBackgroundWithColors:@[[UIColor chColorWithHexString:@"#AEAAFF"],[UIColor chColorWithHexString:@"#8680FC"]] locations:@[@(0.0f), @(1.0f)]  startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
        [btnToHome setTitle:@"直接进入广场，开启寻缘之旅" forState:UIControlStateNormal];
        btnToHome.titleLabel.font = [UIFont systemFontOfSize:16];
        [btnToHome setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btnToHome addTarget:self action:@selector(clickToHome) forControlEvents:UIControlEventTouchUpInside];
        btnToHome.layer.cornerRadius = 23;
        btnToHome.layer.masksToBounds = YES;
        [_viewBottom addSubview:btnToHome];
        self.btnHome = btnToHome;
        
    }
    return _viewBottom;
}

- (BLInfoInputModel *)baseData{
    if (!_baseData) {
        _baseData = [[BLInfoInputModel alloc]init];
    }
    return _baseData;
}

- (BLInfoInputDetailModel *)detailData{
    if (!_detailData) {
        _detailData = [[BLInfoInputDetailModel alloc]init];
    }
    return _detailData;
}
@end
